﻿<script type="text/javascript">

	jQuery(document).ready(function(){
		idcourant = "";
		jQuery(".tohide").hide();
		jQuery(".toshow").show();
		jQuery("img.NumAbonnement").click(function()	{
			id = jQuery(this).attr("id");
			if (id != idcourant) jQuery("div.NumAbonnement").slideUp();
			jQuery("div.NumAbonnement"+id).slideToggle();
			idcourant = id;
		});
	});

</script>

<?php
/**
* @version		$Id: view.html.php 9764 2007-12-30 07:48:11Z ircmaxell $
* @package		Joomla
* @subpackage	Poll
* @copyright	Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license		GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/


// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

jimport( 'joomla.application.component.view');
		
class amapViewgestcontratspr extends JView		{
	var $amap;
	
	function display($tpl = null)	{
		$NomAbonnement = JRequest::getVar('Abonnement');
		$IDA = JRequest::getVar('IDA');
		$action = JRequest::getVar('action');
		
		$url =& JURI::getInstance();
		$this->urlpleine = $url->toString();
		$url->delVar('action');$url->delVar('IDA');$url->delVar('Abonnement');
		$this->urlvide = $url->toString();

		switch ($action)	{
			case 'ValideAbo' :
				$this->gestcontratspr_ChangerStatutAbonnement($IDA, $NomAbonnement, "Abonne");
				break;
			case 'NoValideAbo' :
				$this->gestcontratspr_ChangerStatutAbonnement($IDA, $NomAbonnement, "Encours");
				break;
		}
		
		echo '<h3 class="amap_titre">Gestion des souscriptions aux abonnements</h3>';
		echo 'Vous êtes personne relai pour les abonnements suivants. Sur quels souscriptions d\'abonnement souhaitez-vous intervenir ?<br>';
		echo '<table width="100%"><tr>';
		foreach ($this->amap->adherent as $k=>$d)	if (substr($k, 0, 5) == "relai" AND $d != "") echo '<td style="background-color:'.(($NomAbonnement != $d)?'#3d3a38;':'#0096d2;').' border: solid 5px #3d3a38; padding: 4px;" align="center"><a href="'.$this->urlvide.'&Abonnement='.$d.'">'.$d.'</a></td>';
		echo '</tr></table>';
		if ($NomAbonnement == "")	{	parent::display($tpl); return;	}
		
		$query = "SELECT  adh.Nom as NomFamille, aa.Statut as StatutAbonnement, adh.*, aa.*, abo.*
					FROM amap_abonnementadherent as aa
					LEFT JOIN amap_adherent as adh
						ON aa.IDA = adh.IDA
					LEFT JOIN amap_abonnement as abo
						ON aa.NomAbonnement = abo.Nom
					WHERE aa.NomAbonnement = '".$NomAbonnement."'";
		//~ echo $query;
		$db=&JFactory::getDBO();
		$db->setQuery($query);
		$db->query($query);
		$ListeAbonnements=$db->loadAssocList();
		$NbStatuts["Encours"] = 0;$NbStatuts["Abonne"] = 0;
		foreach ($ListeAbonnements as $Abonnement)	$NbStatuts[$Abonnement["StatutAbonnement"]]++;
		//~ print_r($ListeAbonnements);
			
		//~ Affichage d'un bandeau récapitulant les données de l'amap et du compte de l'amapien
		echo '<br/><div class="amap_info">
		<div style="font-size: 16px; text-transform:uppercase; font-weight: bold; text-decoration: underline;">Informations</div>
		Cet abonnement concerne <b style="color: red;">'.sizeof($ListeAbonnements).' Adhérent(s)</b>.<br/>
		Pour le moment, <b style="color: red;">'.$NbStatuts["Encours"].' abonnement(s)</b> reste(nt) à valider.
		</div>';
		
		echo '<br/><table width="100%" cellpadding="5">
			<tr class="amap_beautableau" style="background-color: #0096D2; color: white;">
				<td align="center" colspan="2" rowspan="2" valign="top"><b>Adhérent</b></td>
				<td align="center" colspan="3" valign="top"><b>Statut</b></td>
			</tr>
			<tr class="amap_beautableau" style="background-color: #0096D2; color: white;">
				<td align="center">En cours</td>
				<td align="center">&nbsp;</td>
				<td align="center">Abonné</td>
			</tr>';
		
		$NumAbonnement = 0;
		foreach ($ListeAbonnements as $Abonnement)	{
			//~ print_r($Abonnement);
			$NumAbonnement++;
			echo '<tr class="amap_beautableau">
				<td width="30" valign="top"><img width="24" height="24" border="0"  src="components/com_amap/images/zoom.png" title="Détails" class="lien NumAbonnement" id="'.$NumAbonnement.'"></td>
				<td><b>'.FormatNomsAdh($Abonnement["NomFamille"], $Abonnement["Prenom"]).'</b></td>';
				if ($Abonnement["StatutAbonnement"] == "Abonne") echo '<td>&nbsp;</td><td align="center"><a href="'.$url->toString().'&action=NoValideAbo&IDA='.$Abonnement["IDA"].'&Abonnement='.$Abonnement["NomAbonnement"].'"><img src="'.JURI::root().'components/com_amap/images/arrow_left.png" title="Passer l\'abonnement en \'En cours\'" width="24" style="padding: 5px;"></a></td>';
				echo '<td align="center"><img width="24" height="24" border="0"  src="components/com_amap/images/bullet_accept.png" title="Dates" class="" id=""></td>';
				if ($Abonnement["StatutAbonnement"] == "Encours") echo '<td align="center"><a href="'.$url->toString().'&action=ValideAbo&IDA='.$Abonnement["IDA"].'&Abonnement='.$Abonnement["NomAbonnement"].'"><img src="'.JURI::root().'components/com_amap/images/arrow_right.png" title="Valider la demande" width="24" style="padding: 5px;"></a></td><td>&nbsp;</td>';
			echo '</tr>';
			//~ La première ligne du tableau ci-dessous est là pour faire conincider les couleurs du tableau
			$detailsproduits = '<blockquote><u>Options de l\'abonnement</u></br>';
			$tmp = "";
			for ($i = 1; $i<11 ; $i++)	if ($Abonnement["QuantiteOption".$i] != 0) $tmp .= $Abonnement["QuantiteOption".$i]." ".$Abonnement["Option".$i]."<br>";
			$detailsproduits .= substr($tmp, 0, strlen($tmp)-4);
			$detailsproduits .= '</blockquote>';
			echo '<tr style="display: none;" class="amap_beautableau"><td></td></tr>
			<tr class="amap_beautableau"><td colspan="5" style="padding: 0px;"><div class="NumAbonnement NumAbonnement'.$NumAbonnement.' tohide" style="background-color: yellow;margin-left: 4px;">'.$detailsproduits.'</div></td></tr>';
		}
		echo '</table>';
		parent::display($tpl);
	}

	//~ Changement de statut d'un abonnement
	function gestcontratspr_ChangerStatutAbonnement ($IDA, $NomAbonnement, $Statut)	{
		$Periode = JRequest::getVar('Periode');
		$db=&JFactory::getDBO();
		$query = "UPDATE amap_abonnementadherent SET Statut = '".$Statut."'	WHERE IDA = '".$IDA."' AND NomAbonnement = '".$NomAbonnement."'";
		$db->setQuery($query);
		$db->query($query);
	}
	
}

?>
